<h:form id="formAcao" 
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets" >

    <script language="JavaScript" src = "scripts/script.js"/>

    <h:panelGrid columns="3" style="width: 100%">

        <h:panelGroup>

            <h:outputLabel value="Número*"/><br/>
            <p:inputMask value="#{acaoBean.acao.numeroAcao}"
                         required="true" 
                         requiredMessage="O campo núm ação requerido" 
                         mask="9999" size="5"/>

        </h:panelGroup>


        <h:panelGroup>

            <h:outputLabel value="Programa"/><br/>
            <p:outputLabel value="#{acaoBean.acao.programa}" 
                           style="color: tomato" />

        </h:panelGroup>

        <h:panelGroup>

            <h:outputLabel value="Período"/><br/>
            <p:outputLabel value="#{acaoBean.acao.periodoDePrograma.anoInicial} 
                           à #{acaoBean.acao.periodoDePrograma.anoFinal}" 
                           style="color: tomato" />

        </h:panelGroup>

    </h:panelGrid>

    <h:panelGrid columns="2" style="width: 100%">

        <h:panelGroup>

            <h:outputLabel value="Tipo de Ação*"/><br/>
            <p:selectOneMenu  id="cbxTiposDeAcao" 
                              value="#{acaoBean.acao.tipoAcao}" 
                              style="width: 204px"
                              required="true" 
                              requiredMessage="O campo tipo de ação é requerido"
                              filter="true" filterMatchMode="startsWith" >

                <f:selectItem itemLabel="Selecione" />
                <f:selectItems value="#{acaoBean.tiposAcao}" />
                <f:converter converterId="simpleEntityConverter" />

            </p:selectOneMenu>

        </h:panelGroup>

        <h:panelGroup>
            <h:outputLabel value="Implementação da Ação*"/><br/>
            <p:selectOneMenu  id="cbxImplementacaoDaAcao" 
                              value="#{acaoBean.acao.formaDeImplementacaoDaAcao}" 
                              style="width: 204px"
                              required="true" 
                              requiredMessage="O campo tipo de ação é requerido"
                              filter="true" 
                              filterMatchMode="startsWith" >

                <f:selectItem itemLabel="Selecione" />
                <f:selectItems value="#{acaoBean.formasImplementacaoDaAcao}" />
                <f:converter converterId="simpleEntityConverter" />

            </p:selectOneMenu>
        </h:panelGroup>

    </h:panelGrid>

    <h:panelGrid columns="2" style="width: 100%">

        <h:panelGroup >
            <h:outputLabel value="Responsável*"/><br/>
            <p:selectOneMenu  id="cbxGestores" 
                              value="#{acaoBean.acao.responsavel}" 

                              filter="true" 
                              filterMatchMode="startsWith" 
                              style="width: 204px" >

                <f:selectItem itemLabel="Selecione" />
                <f:selectItems value="#{acaoBean.gestores}" />
                <f:converter converterId="simpleEntityConverter" />

            </p:selectOneMenu>
        </h:panelGroup>

        <h:panelGroup>
            <h:outputLabel value="Unidade de Medida*"/><br/>
            <p:selectOneMenu id="cbxUnidadesDeMedida" 
                             value="#{acaoBean.acao.unidadeDeMedida}" 
                             required="true" 
                             requiredMessage="O campo uni. medida é requerido"
                             filter="true" 
                             filterMatchMode="startsWith" 
                             style="width: 204px" >

                <f:selectItem itemLabel="Selecione" />
                <f:selectItems value="#{acaoBean.unidadesDeMedida}" />
                <f:converter converterId="simpleEntityConverter" />

            </p:selectOneMenu>
        </h:panelGroup>

    </h:panelGrid>

    <h:panelGrid columns="1" style="width: 100%">

        <h:panelGroup>

            <h:outputLabel value="Sub Função*"/><br/>
            <p:selectOneMenu value="#{acaoBean.acao.subFuncao}" 
                             required="true" 
                             requiredMessage="O campo sub função é requerido"
                             filter="true" 
                             filterMatchMode="startsWith" 
                             style="width: 414px" >

                <f:selectItem itemLabel="Selecione" />
                <f:selectItems value="#{acaoBean.subFuncoes}" />
                <f:converter converterId="simpleEntityConverter" />

            </p:selectOneMenu>
        </h:panelGroup>

    </h:panelGrid>

    <h:panelGrid columns="1" style="width: 100%">

        <h:panelGroup>

            <h:outputLabel value="Descrição*"/><br/>
            <p:inputText styleClass="up"
                         value="#{acaoBean.acao.descricao}" 
                         required="true" 
                         maxlength="80"
                         requiredMessage="O campo descrição é requerido" 
                         style="width: 97%" />

        </h:panelGroup>

        <h:panelGroup>

            <h:outputLabel value="Púlbico Alvo*"/><br/>
            <p:inputText   styleClass="up"  
                           value="#{acaoBean.acao.publicoAlvo}" 
                           required="true" 
                           maxlength="80"
                           requiredMessage="O campo público allvo é requerido" 
                           style="width: 97%"/>

        </h:panelGroup>

        <h:panelGroup>
            <h:outputLabel value="Objetivo*"/><br/>
            <p:inputTextarea   styleClass="up"  
                               value="#{acaoBean.acao.objetivo}" 
                               required="true" 
                               requiredMessage="O campo objetivo é requerido" 
                               style="width: 97%"
                               autoResize="false" />
        </h:panelGroup>

    </h:panelGrid>

    <h:panelGrid style="width: 100%">

        <h:panelGroup>

            <p:dataTable id="dtRegioes" 
                         var="item" value="#{regiaoBean.regioes}"
                         emptyMessage="Não há dados" 
                         paginator="true" 
                         rows="1"
                         rowsPerPageTemplate="1,2,3,4,5,10" >

                <p:column headerText="Opções" 
                          style="width: 30px" >

                    <p:commandButton icon="ui-icon-pencil" 
                                     oncomplete="dlgRegiao.show()" 
                                     update=":panelAddRegiao" >

                        <f:setPropertyActionListener target="#{regiaoBean.regiao}" 
                                                     value="#{item}" />

                    </p:commandButton>

                    <p:commandButton icon="ui-icon-trash" 
                                     actionListener="#{regiaoBean.excluirInicio}" 
                                     immediate="true">

                        <f:setPropertyActionListener target="#{regiaoBean.regiao}" 
                                                      value="#{item}" />

                    </p:commandButton>

                </p:column>

                <p:column headerText="Região">
                    #{item.nome}
                </p:column>

                <f:facet name="footer">
                    <div align="right" >
                        Meta Física:
                        <h:outputText value="#{acaoBean.acao.metaFisica}" />
                    </div>
                </f:facet>

            </p:dataTable>

            <div align="right">

                <p:commandButton icon="ui-icon-plus" 
                                 title="Adicionar" 
                                 immediate="true" 
                                 actionListener="#{regiaoBean.adicionarInicio}" 
                                 onclick="dlgRegiao.show()" 
                                 update=":panelAddRegiao" />

            </div>

        </h:panelGroup>

    </h:panelGrid>

    <hr/>

    <p:commandButton id="btnGravar" value="Gravar" 
                     actionListener="#{acaoBean.adicionarEditarFim}"
                     update="formAcao" />

    <p:commandButton value="Cancelar" 
                     actionListener="#{acaoBean.cancelar}"
                     immediate="true"/>

</h:form>

